import { request } from "../../request/index.js";

// index.js
// @import (request) "/request/index.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperList:[],
    classList:[],
    floorList:[]
  },

  onLoad:function(options){

    // 1网络请求优化手段可以通过es6的promise来解决这个问题 
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   success: (result) => {
    //       console.log(result.data.message);
    //       this.setData({
    //         swiperList:result.data.message
    //       })
    //   },
    // })
    this.getBannerList();
    this.getClassList();
    this.getFloorList();
  },
getBannerList(){
request({url:'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata'})
.then(result=>{
  this.setData({
    swiperList:result.data.message
  })
})
},
  
getClassList(){
  request({url:"https://api-hmugo-web.itheima.net/api/public/v1/home/catitems"})
  .then(result=>{
    this.setData({
      classList:result.data.message
    })
  })
},


getFloorList(){
  request({url:"https://api-hmugo-web.itheima.net/api/public/v1/home/floordata"})
  .then(result=>{
    this.setData({
      floorList:result.data.message
    })
  })
}
})
